﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using BaMusaSoft.RPS.ViewModel;
using BaMusaSoft.RPS.DataModel.Repositories;
using System.Linq;
using BaMusaSoft.RPS.DataModel;
using BaMusaSoft.RPS.View.Services;
namespace BaMusaSoft.RPS.View
{
	/// <summary>
	/// Interaction logic for ClaimViewWindow.xaml
	/// </summary>
	public partial class ClaimViewWindow : Window
	{
		//ClaimViewModel vm;
		public ClaimViewWindow()
		{
			this.InitializeComponent();
			
			// Insert code required on object creation below this point.
		}
        //public ClaimViewWindow(ClaimViewModel vm):this()
        //{
        //    this.vm = vm;
        //    this.DataContext = this.vm; ;
        //}

		private void WindowLoaded(object sender, RoutedEventArgs e)
		{
            //vm.AddCustomerRequest += new EventHandler<NotifyEventArgs<DataModel.Customer>>(AddCustomerRequest);
            //vm.AddDetailsRequest += new EventHandler<NotifyEventArgs<IList<Contract>>>(AddDetailsRequest);
            //vm.AddOutboxRequest += new EventHandler<NotifyEventArgs<Tuple<Outbox, bool>>>(AddOutboxRequest);
            //vm.MessageNotification +=new EventHandler<NotificationEventArgs>(Helper.MessageNotificationEvent);

		}

        //void AddOutboxRequest(object sender, NotifyEventArgs<Tuple<Outbox, bool>> e)
        //{
        //    Outbox outbox = new Outbox();
        //    OutboxRepository repo = new OutboxRepository();
        //    using (OutboxViewModel outboxVm = new OutboxViewModel(outbox, repo))
        //    {
        //        AddOutboxWindow addOutobx = new AddOutboxWindow(outboxVm);
        //        addOutobx.Closed += (s, ea) =>
        //        {
        //            if (addOutobx.DialogResult == true)
        //            {
        //                Outbox outboxObj = outboxVm.CurrentOutbox;
        //                Tuple<Outbox, bool> t = new Tuple<Outbox, bool>(outboxObj, outboxVm.AutoIncrementOutboxNo);
        //                e.Callback(t);
        //            }
        //        };
        //        addOutobx.Owner = this;
        //        addOutobx.ShowDialog();
        //    }
        //}

        //void AddDetailsRequest(object sender, NotifyEventArgs<IList<Contract>> e)
        //{
        //    if (vm.Customer == null)
        //    {
        //        Helper.NotificationMessageBox("يجب إختيار مستأجر أولاً");
        //        return;
        //    }

        //    using (ContractViewModel contractVM = new ContractViewModel(vm.Customer.CustomerId))
        //    {
        //        AddClaimDetailsWindow addClaimsDetails = new AddClaimDetailsWindow(contractVM);
        //        addClaimsDetails.Closed += (s, ea) =>
        //        {
        //            if (addClaimsDetails.DialogResult == true)
        //            {
        //                IList<Contract> selectedContracts = contractVM.SelectedContracts;

        //                e.Callback(selectedContracts);
        //            }
        //        };
        //        addClaimsDetails.Owner = this;
        //        addClaimsDetails.ShowDialog();
        //    }
        //}

        //void AddCustomerRequest(object sender, NotifyEventArgs<DataModel.Customer> e)
        //{
        //    CustomerRepository repo = new CustomerRepository();
        //    var list = repo.GetAll().ToList();
        //    using (CustomerViewModel customerVM = new CustomerViewModel(repo, list))
        //    {
        //        AddCustomerWindow customersSelection = new AddCustomerWindow(customerVM);
        //        customersSelection.Closed += (s, ea) =>
        //        {
        //            if (customersSelection.DialogResult == true)
        //            {
        //                //Customer customer = ((CustomerViewModel)customersSelection.DataContext).SelectedCustomer;
        //                Customer customer = customerVM.SelectedCustomer;
        //                e.Callback(customer);
        //            }
        //        };
        //        customersSelection.Owner = this;
        //        customersSelection.ShowDialog();
        //    }
        //}

		private void WinodwClosing(object sender, System.ComponentModel.CancelEventArgs e)
		{
            //vm.AddCustomerRequest -= new EventHandler<NotifyEventArgs<DataModel.Customer>>(AddCustomerRequest);
            //vm.AddDetailsRequest -= new EventHandler<NotifyEventArgs<IList<Contract>>>(AddDetailsRequest);
            //vm.AddOutboxRequest -= new EventHandler<NotifyEventArgs<Tuple<Outbox, bool>>>(AddOutboxRequest);


		}

	}
}